home *** CD-ROM | disk | FTP | other *** search
- ******************************************************************
- * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
- * - Note: This is a real, live, actual, registered copyright,
- * and should be treated as such. This source code is from
- * the book "68000 Assembly Language", Krantz and Stanley,
- * Addison-Wesley Publishing Company, Reading, MA, 1986.
- *
- * Permission granted by the authors for non-commercial use
- * in programs released to the public domain, as long as this
- * copyright notice remains attached and visible.
- *
- *****************************************************************
- * SQRT - Integer floored square root
- * Entry: D0.L = number to take root of
- * Exit: D0.L = square root
-
- xdef sqrt
-
- sqrt:
- movem.l d1-d3,-(a7)
- clr.l d1 * D1 will be test case root
- move.w #$8000,d2 * D2 is succ. aprox. mask
- lp1:
- or.w d2,d1 * load in mask value
- move.w d1,d3 * d3 is a scratch register
- mulu d3,d3 * make a try
- cmp.l d3,d0 * take a look - how'd we do?
- bhi sk1 * try less than goal - keep bit
- not.w d2 * we need to mask bit out
- and.w d2,d1 * take out trial bit
- not.w d2 * fix mask
- sk1:
- lsr.w #1,d2 * move mask down
- bcc lp1 * mask mot done - go around.
- sq_exit:
- move.l d1,d0 * transfer answer
- movem.l (a7)+,d1-d3 * restore registers
- rts